﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyTypeAddControl : YuanlinUserControl
    {
        protected ValuedTextBox titleValuedTextBox;

        protected IButton SaveButton;
        protected IButton BackButton;

        protected override void OnLoad(EventArgs e)
        {
            SaveButton.Click += new EventHandler(SaveButton_Click);
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect(SiteUrls.Instance().GetCompanyTypeListUrl());
        }

        public void SaveButton_Click(object sender, EventArgs e)
        {
            if (titleValuedTextBox.Value.Trim().Length == 0)
            {
                Globals.ShowMessage(this.Page, "CompanyTypeAddControl", "请输入名称！");
                return;
            }
            CompanyType companyType = new CompanyType();
            
            companyType.Title.Value =  CensorWordManager.CensorWord(this.titleValuedTextBox.Value);

            if (BusinessManager.CreateCompanyType(companyType) == -2)
            {
                Globals.ShowMessage(this.Page, "添加失败", "此信息已经存在！");
                return;
            }

            Page.Response.Redirect(SiteUrls.Instance().GetCompanyTypeListUrl());
        }
    }
}